# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.

from odoo import api, fields, models, _

import datetime



import logging
_logger = logging.getLogger(__name__)

class CrEmpStop(models.Model):

    _name = "cr.emp.stop"
    _description = "阻断"

    name = fields.Char(string='标题')
    detail = fields.Text(string='内容')


class CrEmpInspire(models.Model):

    _name = "cr.emp.inspire"
    _description = "激励"

    name = fields.Char(string='姓名',related='staff_id.name',store=True)
    card_id = fields.Char(string='工号',related='staff_id.card_id',store=True)
    ws_id = fields.Many2one('cr.emp.workshop', string='所属车间', related='staff_id.ws_id',store=True)
    team_id = fields.Many2one("cr.emp.team", string='班组', related='staff_id.team_id',store=True)
    post_id = fields.Many2one("cr.emp.post", string='岗位', related='staff_id.post_id',store=True)
    staff_id = fields.Many2one('cr.emp.staff',string='员工')

    add_score = fields.Integer(string='奖励积分',related='score_id.add_score',store=True)
    sub_score = fields.Integer(string='处罚积分',related='score_id.add_score',store=True)
    total_score = fields.Integer(string='总积分',related='score_id.add_score',store=True)
    score_id = fields.Many2one('cr.emp.score',string='积分条目')

    detail=fields.Text(string='评价')
    add_money = fields.Float(string='奖金',default=0)
    sub_money = fields.Float(string='罚款',compute='_compute_score',store=True)
    end_money = fields.Float(string='最终核算',default=300)
    is_lose = fields.Boolean(string='是否失信')
    is_check = fields.Boolean(string='考核完成')

    year = fields.Char(string='年份')
    month = fields.Char(string='月份')


    @api.depends('total_score')
    def _compute_score(self):
        for i in self:
            if i.total_score >= 90:
                i.sub_money=300
            elif i.total_score < 90 and i.total_score>=60:
                i.sub_money=270
            else:
                i.sub_money=0
            i.end_money=i.add_money + i.sub_money




